$(document).ready(function(){
   
    //礼包列
    var htmlgame = '';
    var listgame = [];
    listgame = [
        {
            gamenamemin:'zytl',
            gameimg:'images/cyhc.png',
            gamename:'斩月屠龙',
            gametitle:'刀在手，跟我走，跟着鳌拜，啥都有',
            gifts:[
                {
                    giftname:'新手礼包1-1',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                },
                {
                    giftname:'新手礼包1-2',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'zcry',
            gameimg:'images/zcry.png',
            gamename:'战场荣耀',
            gametitle:'刀在手，跟我走，跟着刀在手，跟我走，跟着',
            gifts:[
                {
                    giftname:'新手礼包2-1',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }, {
                    giftname:'新手礼包2-2',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'rxhmc',
            gameimg:'images/rxhmc.png',
            gamename:'热血红名村',
            gametitle:'刀在手，跟我走，跟着刀在手，跟我走，跟着',
            gifts:[
                {
                    giftname:'新手礼包3-1',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }, {
                    giftname:'新手礼包3-2',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }, {
                    giftname:'新手礼包3-3',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        }
    ];

    var gamesBox = [
        {gamename:'斩月屠龙1'},
        {gamename:'斩月屠龙2'},
        {gamename:'斩月屠龙3'},
        {gamename:'斩月屠龙4'}
    ];


    if(listgame.length<1){
        // console.log("小于一")
        $('.hotGameBox').addClass('disn').removeClass('disb')
        $('.nocenBox').addClass('disb').removeClass('disn')
    }else{
        // console.log("大于一")
        $('.hotGameBox').addClass('disb').removeClass('disn')
        $('.nocenBox').addClass('disn').removeClass('disb')
        for(var i=0;i<listgame.length;i++){
            var gifts = listgame[i].gifts;
            var htmlgift = '';            
            htmlgame += '<div class="planCenBox">'+
                            '<div class="planImg"><img src="'+listgame[i].gameimg+'" /></div>'+
                            '<div class="planCen">'+
                                '<p>'+listgame[i].gamename+'<span class="planhot"></span></p>'+
                                '<p>'+listgame[i].gametitle+'</p>'+
                            '</div>'+
                            '<div class="palnBtn">'+
                                '<button onclick="enterGame(\''+listgame[i].gamenamemin+'\')">开始</button>'+
                            '</div>'+
                            '<div class="giftBoxs">'
                            if(gifts.length<1){
                            }else{
                                for(var j =0;j<gifts.length;j++){
                                    htmlgift += '<div class="giftBox">'+
                                                    '<div class="giftBoxLeft">'+
                                                        '<i></i>'+
                                                        '<p>'+gifts[j].giftname+'</p>'+
                                                    '</div>'+
                                                    '<div class="giftBoxRight">'+gifts[j].giftText+'</div>'+
                                                    '<div class="gitgift" onclick="gitgift()">'+
                                                        '<a><img src="images/gift_right.png" /></a>'+
                                                    '</div>'+
                                                '</div>'
                                }                
                            }
            htmlgame += htmlgift;
            htmlgame += '</div>'+
                            '<div class="more">'+
                                '<p><span>更多礼包('+gifts.length+')</span><samp></samp></p>'+
                            '</div>'+
                        '</div>'
        }        
        $(".havegames").html(htmlgame)        
    };

    //更多
    $(".more").click(function(){
        $(this).siblings(".giftBoxs").toggle()
    });

    //选择点击热门游戏块
    $(".hotGames").on("click",'text',function(){
        console.log($(this).text())
        $('.searchinput').val($(this).text())
    });

    //热门游戏
    var gameBox  = '';
    for(var i=0;i<gamesBox.length;i++){
        gameBox += '<text>'+gamesBox[i].gamename+'</text>'
    }
    $('.hotGames').html(gameBox)
})

//领取礼包
function gitgift(){
    $(".bouncedBg").addClass('disb').removeClass('disn')
}
//关闭弹框
function closegit(){
    $(".bouncedBg").addClass('disn').removeClass('disb')
}